
export type EQExecInfo = {
    command: string;
    args: string[];

    eq: string[];
    eqExecutable: string;
};

export function buildEQExecInfo(
    eq: string | string[],
    eqArgs?: string[],
    eqExecutable?: string,
): EQExecInfo {
    if (Array.isArray(eq)) {
        const args = eq.slice(1);
        if (eqArgs) {
            args.push(...eqArgs);
        }
        return {
            args,
            command: eq[0],
            eq: [...eq],
            eqExecutable: eqExecutable ?? eq[eq.length - 1],
        };
    }
    return {
        command: eq,
        args: eqArgs || [],
        eq: [eq],
        eqExecutable: eq,
    };
}

export function copyEQExecInfo(orig: EQExecInfo, extraEQArgs?: string[]): EQExecInfo {
    const info = {
        command: orig.command,
        args: [...orig.args],
        eq: [...orig.eq],
        eqExecutable: orig.eqExecutable,
    };
    if (extraEQArgs) {
        info.args.push(...extraEQArgs);
    }
    if (info.eqExecutable === undefined) {
        info.eqExecutable = info.eq[info.eq.length - 1]; // Default case
    }
    return info;
}